"""
https://leetcode.cn/problems/container-with-most-water/description/
"""
from typing import List


def max_area(height: List[int]) -> int:
    """leetcode 11.盛水最多的容器 - 暴力求解

    Args:
        height (List[int]): 输入

    Returns:
        int: 最大容量
    """
    if len(height) < 2:
        return 0

    area = 0
    for i in range(len(height)):
        for j in range(i+1, len(height)):
            width = j - i
            min_height = min([height[i], height[j]])
            if width * min_height >= area:
                area = width * min_height
    return area


def max_area_by_two_point(height: List[int]) -> int:
    """leetcode 11.盛水最多的容器 - 双指针求解

    Args:
        height (List[int]): 输入

    Returns:
        int: 最大容量
    """
    point_left: int = 0
    point_right: int = len(height) - 1
    area: int = 0

    while point_left < point_right:
        if height[point_left] <= height[point_right]:
            area = max(area, height[point_left] * (point_right - point_left))
            point_left += 1
        else:
            area = max(area, height[point_right] * (point_right - point_left))
            point_right -= 1
    return area


if __name__ == "__main__":
    h = [2, 3, 4, 5, 18, 17, 6]
    print(max_area(h))
    print(max_area_by_two_point(h))
